module Detector2 (
input CP,Sin,nCR,
output reg Out
);

reg [1:0] Current_state,Next_state;
parameter S0=2'b00, S1=2'b01, S2=2'b10, S3=2'b11;
always @(posedge CP , negedge nCR)
begin
  if(~nCR) 
      begin
        Current_state = S0;
        Next_state = S0;
      end
      
  else
      Current_state = Next_state;
end
always @(Current_state, Sin)
begin
  Next_state=2'bxx;
  Out=1'b 0;
  case(Current_state)
    S0: begin Out=1'b0; Next_state=(Sin==1)? S0 : S1; end
    S1: begin Out=1'b0; Next_state=(Sin==1)? S2 : S1; end
    S2: begin Out=1'b0; Next_state=(Sin==1)? S0 : S3; end
    S3: if (Sin==1)
    begin Out=1'b1; Next_state=S0;  end
    else
    begin Out =1'b0; Next_state=S1; end
  endcase
end
endmodule